package com.qianying.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianying.comment.CommonResult;
import com.qianying.entity.PlatformCompany;
import com.qianying.service.PlatformCompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 平台公司Controller（管理员接口）
 * 提供符合Swagger 3.x规范的平台公司管理接口
 */
@RestController
@RequestMapping("/admin/platformCompany")
@Tag(name = "平台公司管理", description = "平台公司的增删改查操作接口")
public class PlatformCompanyController {

    @Autowired
    private PlatformCompanyService platformCompanyService;

    /**
     * 分页查询平台公司列表
     */
    @GetMapping("/getPage")
    @Operation(
            summary = "分页查询公司列表",
            description = "支持按公司名称模糊查询，返回分页数据列表"
    )
    public CommonResult<Page<PlatformCompany>> getPage(
            @Parameter(description = "页码（默认1）", example = "1")
            @RequestParam(defaultValue = "1") Integer current,
            @Parameter(description = "每页条数（默认10）", example = "10")
            @RequestParam(defaultValue = "10") Integer size,
            @Parameter(description = "公司名称（模糊查询，可选）", example = "科技公司")
            @RequestParam(required = false) String companyName) {
        Page<PlatformCompany> page = new Page<>(current, size);
        return platformCompanyService.getPage(page, companyName);
    }

    /**
     * 根据ID查询公司详情
     */
    @GetMapping("/getById")
    @Operation(
            summary = "查询公司详情",
            description = "通过公司ID获取完整信息"
    )
    public CommonResult<PlatformCompany> getById(
            @Parameter(description = "公司ID", required = true, example = "1")
            @RequestParam Long id) {
        return platformCompanyService.getById(id);
    }

    /**
     * 新增平台公司
     */
    @PostMapping("/saveCompany")
    @Operation(
            summary = "新增平台公司",
            description = "创建新的平台公司记录，公司名称为必填项",
            parameters = {
                    @Parameter(name = "companyName", description = "公司名称", example = "北京科技有限公司"),
                    @Parameter(name = "companyAbbreviation", description = "公司简称", example = "北科"),
                    @Parameter(name = "taxNumber", description = "税号", example = "91110108XXXXXXXXXX"),
                    @Parameter(name = "taxRate1", description = "税率1", example = "13"),
                    @Parameter(name = "taxRate2", description = "税率2", example = "9"),
                    @Parameter(name = "taxRate3", description = "税率3", example = "6"),
                    @Parameter(name = "enabledStatus", description = "启用状态", example = "true"),
                    @Parameter(name = "description", description = "描述", example = "专注于科技服务的平台公司")
            }
    )
    public CommonResult<?> saveCompany(@RequestBody PlatformCompany company) {
        return platformCompanyService.saveCompany(company);
    }

    /**
     * 更新平台公司信息
     */
    @PostMapping("/updateCompany")
    @Operation(
            summary = "更新平台公司",
            description = "修改已有平台公司信息，必须包含ID和公司名称",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", example = "1"),
                    @Parameter(name = "companyName", description = "公司名称", example = "北京科技有限公司"),
                    @Parameter(name = "companyAbbreviation", description = "公司简称", example = "北科"),
                    @Parameter(name = "taxNumber", description = "税号", example = "91110108XXXXXXXXXX"),
                    @Parameter(name = "taxRate1", description = "税率1", example = "13"),
                    @Parameter(name = "taxRate2", description = "税率2", example = "9"),
                    @Parameter(name = "taxRate3", description = "税率3", example = "6"),
                    @Parameter(name = "enabledStatus", description = "启用状态", example = "true"),
                    @Parameter(name = "description", description = "描述", example = "专注于科技服务的平台公司")
            }
    )
    public CommonResult<?> updateCompany(@RequestBody PlatformCompany company) {
        return platformCompanyService.updateCompany(company);
    }

    /**
     * 根据ID删除平台公司
     */
    @PostMapping("/removeById")
    @Operation(
            summary = "删除平台公司",
            description = "通过公司ID删除指定记录"
    )
    public CommonResult<?> removeById(
            @Parameter(description = "公司ID", required = true, example = "1")
            @RequestParam Long id) {
        return platformCompanyService.removeById(id);
    }
}
